package com.danciyixue.boot.dcyx.controller;

import com.danciyixue.boot.dcyx.service.SeriesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.danciyixue.boot.dcyx.model.form.SeriesForm;
import com.danciyixue.boot.dcyx.model.query.SeriesQuery;
import com.danciyixue.boot.dcyx.model.vo.SeriesVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.danciyixue.boot.common.result.PageResult;
import com.danciyixue.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 系列信息前端控制层
 *
 * @author youlaitech
 * @since 2025-06-15 16:29
 */
@Tag(name = "系列信息接口")
@RestController
@RequestMapping("/api/v1/series")
@RequiredArgsConstructor
public class SeriesController  {

    private final SeriesService seriesService;

    @Operation(summary = "系列信息分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('dcyx:series:query')")
    public PageResult<SeriesVO> getSeriesPage(SeriesQuery queryParams ) {
        IPage<SeriesVO> result = seriesService.getSeriesPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增系列信息")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('dcyx:series:add')")
    public Result<Void> saveSeries(@RequestBody @Valid SeriesForm formData ) {
        boolean result = seriesService.saveSeries(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取系列信息表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('dcyx:series:edit')")
    public Result<SeriesForm> getSeriesForm(
        @Parameter(description = "系列信息ID") @PathVariable Long id
    ) {
        SeriesForm formData = seriesService.getSeriesFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改系列信息")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('dcyx:series:edit')")
    public Result<Void> updateSeries(
            @Parameter(description = "系列信息ID") @PathVariable Long id,
            @RequestBody @Validated SeriesForm formData
    ) {
        boolean result = seriesService.updateSeries(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除系列信息")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('dcyx:series:delete')")
    public Result<Void> deleteSeriess(
        @Parameter(description = "系列信息ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = seriesService.deleteSeriess(ids);
        return Result.judge(result);
    }
}
